package cn.tedu.boot32.controller;


import cn.tedu.boot32.mapper.UserMapper;
import cn.tedu.boot32.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Autowired(required = false)
    UserMapper mapper;

    @RequestMapping("/reg")
    public String reg(User user){
        User u = mapper.selectByUsername(user.getUsername());
        if (u != null){
            return "用户名已经存在";
        }
        mapper.insert(user);
        return "注册成功!";
    }

    @RequestMapping("/login")
    public String login(User user){
        User u = mapper.selectByUsername(user.getUsername());
        if (u != null){
            //user 代表用户传递过来的
            //u代表数据库中正确的信息
            if (u.getPassword().equals(user.getPassword())){
                return "登录成功";
            }
            return "密码错误";
        }
        return "用户名不存在!";

    }


}
